package com.shanling.shanlingcontroller.ui.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.shanling.shanlingcontroller.R;
import com.shanling.shanlingcontroller.base.BaseLazyFragment;
import com.shanling.shanlingcontroller.bean.Constants;
import com.shanling.shanlingcontroller.bean.EventCenter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by ch1 on 2019/12/2.
 */

public class FilterFragment extends BaseLazyFragment {
    @BindView(R.id.iv_frist)
    ImageView ivFrist;
    @BindView(R.id.ll_Linear_phase_fast)
    LinearLayout llLinearPhaseFast;
    @BindView(R.id.iv_second)
    ImageView ivSecond;
    @BindView(R.id.ll_Linear_phase_slow)
    LinearLayout llLinearPhaseSlow;
    @BindView(R.id.iv_third)
    ImageView ivThird;
    @BindView(R.id.ll_Minimum_phase_fast)
    LinearLayout llMinimumPhaseFast;
    @BindView(R.id.iv_fourth)
    ImageView ivFourth;
    @BindView(R.id.ll_Minimum_phase_slow)
    LinearLayout llMinimumPhaseSlow;

    @Override
    protected void onLazyLoad() {
        String filter = preferenceUtil.getFilter();
        setFilter(Byte.parseByte(filter),false);
    }
    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fragment_filter;
    }
    @Override
    protected void initViewsAndEvents() {

    }
    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected void onEventComing(EventCenter eventCenter) {

    }
    @OnClick({R.id.ll_Linear_phase_fast, R.id.ll_Linear_phase_slow, R.id.ll_Minimum_phase_fast, R.id.ll_Minimum_phase_slow})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_Linear_phase_fast:
                setFilter((byte) 1,true);
                break;
            case R.id.ll_Linear_phase_slow:
                setFilter((byte) 2,true);
                break;
            case R.id.ll_Minimum_phase_fast:
                setFilter((byte) 3,true);
                break;
            case R.id.ll_Minimum_phase_slow:
                setFilter((byte) 4,true);
                break;
        }
    }

    public void setFilter(byte filter,boolean isSend){
        switch (filter){
            case 1:
                ivFrist.setVisibility(View.VISIBLE);
                ivSecond.setVisibility(View.INVISIBLE);
                ivThird.setVisibility(View.INVISIBLE);
                ivFourth.setVisibility(View.INVISIBLE);
                break;
            case 2:
                ivFrist.setVisibility(View.INVISIBLE);
                ivSecond.setVisibility(View.VISIBLE);
                ivThird.setVisibility(View.INVISIBLE);
                ivFourth.setVisibility(View.INVISIBLE);
                break;
            case 3:
                ivFrist.setVisibility(View.INVISIBLE);
                ivSecond.setVisibility(View.INVISIBLE);
                ivThird.setVisibility(View.VISIBLE);
                ivFourth.setVisibility(View.INVISIBLE);
                break;
            case 4:
                ivFrist.setVisibility(View.INVISIBLE);
                ivSecond.setVisibility(View.INVISIBLE);
                ivThird.setVisibility(View.INVISIBLE);
                ivFourth.setVisibility(View.VISIBLE);
                break;
        }
        if(isSend){
            EventBus.getDefault().postSticky(new EventCenter<>(Constants.SETFILTER,filter));
        }
    }

}
